var message = require('{layer}/message');
var validate = require('{plus}/validate');

return function(form, options){
    return form.validate($.extend({
        errorClass:'s-err',
        onkeyup:false,
        focusInvalid:false,
        onfocusout:false,
        focusCleanup:true,
        ignore:'',
        success:function(error, element) {
            error.remove();
            $(element).addClass('s-succ');
        },
        errorPlacement:function(error, element) {
            element.removeClass('s-succ');
            if(error.text()){
                element.closest('.ui-item').find('.ui-err').html(error);
                if(element.get(0).nodeName === 'SELECT'){
                    element.closest('.ui-input').addClass('s-err')
                }
            }
        },
        submitHandler:function(){
            var data = util.getData(form).result;
            request.postUpdate('user.json', data, {
                success:function(res){
                    message();
                    if(_layer){
                        _layer.hide();
                        that.paging.query('reload')
                    }
                    else{
                        router.location('/list/')
                    }
                },
                other:function(res){
                    message('error', res.message);
                }
            }, _layer)
            return false
        }
    }), options||{})
}